package com.proba.annotations.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.proba.annotations.EdinicaMerkaDAO;
import com.proba.annotations.pojo.EdinicaMerka;
import com.proba.annotations.pojo.GotovProizvod;

public class EdinicaMerkaHibernateDAO extends
		AbstractHibernateDAO<EdinicaMerka, Long> implements
		EdinicaMerkaDAO {

	/**
	 * Find EdinicaMerka by edinicaMerka
	 */
	public List<EdinicaMerka> findByEdinicaMerka(String edinicaMerka) {
		return findByCriteria(Restrictions.eq("edinicaMerka", edinicaMerka));
	}
	
	/**
	 * Find EdinicaMerka by edinicaMerkaLabel
	 */
	public List<EdinicaMerka> findByEdinicaMerkaLabel(String edinicaMerkaLabel) {
		return findByCriteria(Restrictions.eq("edinicaMerkaLabel", edinicaMerkaLabel));
	}
	
	/**
	 * Find EdinicaMerka by edit
	 */
	public List<EdinicaMerka> findByEdit(String edit) {
		return findByCriteria(Restrictions.eq("edit", edit));
	}

	@Override
	public List<EdinicaMerka> findByFilterParams(int startIndex, int pageSize, Long id,
			String edinicaMerka, String edinicaMerkaLabel) {
		Criteria crit = getCriteria(startIndex, pageSize);
		if (id != null) {
			crit.add(Restrictions.eq("id", id));
		}
		if (edinicaMerka != null && !edinicaMerka.isEmpty()) {
			crit.add(like("edinicaMerka", edinicaMerka));
		}
		return crit.list();
	}

}
